<?php

/**
 * @Project NUKEVIET 3.0
 * @Author VINADES.,JSC (contact@vinades.vn)
 * @Copyright (C) 2010 VINADES., JSC. All rights reserved
 * @Createdate 3-6-2010 0:14
 */

if ( ! defined( 'NV_IS_MOD_SHOPS' ) ) die( 'Stop!!!' );

$page_title = $lang_module['product_compare_title'];
$key_words = $lang_module['product_compare_title'];
$description = $lang_module['product_compare_title'];

$count = 0;
$link = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=";
$base_url = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=" . $global_array_cat[$catid]['alias'] . "";

$sql = "SELECT *  FROM `" . $db_config['prefix'] . "_" . $module_data . "_rows` WHERE ";
$array_cat = $_SESSION['compare'];
//    $array_cat = GetCatidInParent( $catid );
$sql .= " id IN (" . implode( ",", $array_cat ) . ")";
$sql .= " AND status=1 AND publtime < " . NV_CURRENTTIME . " AND (exptime=0 OR exptime>" . NV_CURRENTTIME
. ") ORDER BY ID";
//$_SESSION['shop_viewcat_order']
$result = $db->sql_query( $sql );
$result_page = $db->sql_query( "SELECT FOUND_ROWS()" );
list( $all_page ) = $db->sql_fetchrow( $result_page );

$data_contents = GetDataIn( $result );

$data_contents['count'] = $all_page;
foreach ($array_cat as $id) {
    $query = $db->sql_query( "SELECT * FROM `" . $db_config['prefix'] . "_" . $module_data . "_rows` WHERE `id` = " . $id . " AND status=1 AND publtime < " . NV_CURRENTTIME . " AND (exptime=0 OR exptime>" . NV_CURRENTTIME . ")" );

    $data_content = $db->sql_fetchrow( $query, 2 );
    $data_shop = array();
    if ( empty( $data_content ) )
    {
        $nv_redirect = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=shops";
        redict_link( $lang_module['detail_do_not_view'], $lang_module['redirect_to_back_shops'], $nv_redirect );
    }
    else
    {
        if ( isset( $site_mods['company'] ) )
        {
            $re = $db->sql_query( "SELECT * FROM `" . $db_config['prefix'] . "_company_rows` WHERE `com_id` = " . $data_content['com_id'] . " AND status=1 AND publtime < " . NV_CURRENTTIME . " AND (exptime=0 OR exptime>" . NV_CURRENTTIME . ")" );
            $data_shop = $db->sql_fetchrow( $re, 2 );
        }
        else
        {
            $data_shop = array();
        }
        $catid = $data_content['listcatid'];
    }

    $query = $db->sql_query( "SELECT * FROM `" . $db_config['prefix'] . "_" . $module_data . "_units` WHERE `id` = " . $data_content['product_unit'] . "" );
    $data_unit = $db->sql_fetchrow( $query );
    $data_unit['title'] = $data_unit[NV_LANG_DATA . '_title'];
    ///////////////////////////////////////////////////////////
    $array_img = explode( "|", $data_content['homeimgthumb'] );
    if ( ! empty( $array_img[0] ) && ! nv_is_url( $array_img[0] ) )
    {
        $data_content['homeimgfile'] = NV_BASE_SITEURL . NV_UPLOADS_DIR . "/" . $module_name . "/" . $data_content['homeimgfile'];
        $array_img[0] = NV_BASE_SITEURL . NV_UPLOADS_DIR . "/" . $module_name . "/" . $array_img[0];
    }
    else
    {
        $data_content['homeimgfile'] = NV_BASE_SITEURL . NV_UPLOADS_DIR . "/" . $module_name . "/thumb/no_image.jpg";
        $array_img[0] = NV_BASE_SITEURL . "themes/" . $module_info['template'] . "/images/" . $module_file . "/no-image.jpg";
    }
    $data_content['homeimgthumb'] = $array_img[0];
    
    $data_content["link_pro"] = $link . $global_array_cat[$catid]['alias'] . "/" . $data_content['vi_alias'] . "-" . $id;
    /*end*/
//    $page_title = $data_content[NV_LANG_DATA . '_title'];
//    $link_view = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=" . $global_array_cat[$catid]['alias'] . "/" . $data_content[NV_LANG_DATA . '_alias'] . "-" . $data_content['id'];
//    SetSessionProView( $data_content['id'], $data_content[NV_LANG_DATA . '_title'], $data_content[NV_LANG_DATA . '_alias'], $data_content['addtime'], $link_view, $data_content['homeimgthumb'] );
    $column_content = detail_compare( $data_content, $data_unit, $data_comment, $num_com, $data_others, $data_shop,$array_other_view );
    $data_contents['html'][] = $column_content;
}

$contents = compare_product( $data_contents );

include ( NV_ROOTDIR . "/includes/header.php" );
echo nv_site_theme( $contents );
include ( NV_ROOTDIR . "/includes/footer.php" );

?>